package ticketManagement;

import java.io.Serializable;

import transportManagement.Transport;
import common.Date;

public class SeasonTicket extends Ticket implements Serializable {
	private static final long serialVersionUID = -8565540585324958679L;
	
	private Date beginDate;
	private Date endDate;
	
	public SeasonTicket() {
		super();
	}
	
	public SeasonTicket(Transport corsa, Date dataInizio, Date dataFine) {
		super(corsa);
//		if(dataFine.compareTo(dataInizio) < 0){
//			throw new InvalidParameterException("DataFine deve esser successiva a DataInizio!");
//		}
		this.setEndDate(dataFine);
		this.setBeginDate(dataInizio);
	}

	public Date getBeginDate() {
		return beginDate;
	}
	
	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}
	
	public Date getEndDate() {
		return endDate;
	}
	
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
	
	@Override
	public double getPrize() {
		double result;
		int diffInOre;
		
		diffInOre = endDate.getHourDifference(beginDate);
		int diffInGiorni = (int) (diffInOre / 24);
		result = super.getPrize() * diffInGiorni;
	
		return result;		
	}	
	
	@Override
	public boolean equals(Object object) {
		return object != null && object instanceof SeasonTicket && super.equals((SeasonTicket)object);
	}
	
	public String toString() {
		return "SeasonTicket[" + super.toString() +
				";BeginDate:" + this.getBeginDate() + 
				";EndDate:" + this.getEndDate() + 
				"]";
	}
	
}
